/**
 * @param {number[]} candies
 * @param {number} k
 * @return {number}
 */
 var maximumCandies = function(candies, k) {
  const n = candies.length
  candies.sort((a,b) => a-b)
  let l = 0, r = candies[n-1]
  while(l < r) {
    let m = Math.floor((l+r+1)/2)
    if(ok(m)) {
      l = m
    }else {
      r = m-1
    }
  }
  return l
  function ok(t) {
    let cnt = 0
    for(let x of candies) {
      cnt += Math.floor(x/t)
    }
    return cnt >= k
  }
};